package com.smark.sbrabbitmqfanoutproducer.mq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.UUID;

/**
 * @author smark
 */
@Component
public class UserService {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    //AmqpTemplate是一个接口，最终找到实现类也就是：RabbitTemplate
//    @Autowired
//    private AmqpTemplate template;

    //1、定义交换机
    @Value(value = "${mq.config.exchange}")
    private String exchangeName;



    public void sendMessages(int i){
        String userId= "100";
        String message = i+" ===>保存用户："+userId+",日期是："+new Date();
        //发送消息
        rabbitTemplate.convertAndSend(exchangeName,"email",message);
        rabbitTemplate.convertAndSend(exchangeName,"log",message);
    }


}
